$(function() {
   	

	
	// 分页的下拉列表
	$("#choosePage").click(function(a) {

		$("#chooseUl").empty();
		$("#chooseDiv").toggle();

		var chooseUl = $("#chooseUl");
		var chooseFirst = parseInt($("#chooseFirst").html());
		var chooseFinal = parseInt($("#chooseFinal").html());

		for (var i = 1; i <= chooseFinal; i++) {

			var L = "<li onclick='fl(" + i + ")'>" + i + "</li>";

			chooseUl.append(L);

		}

		scrollTop(chooseFirst);
	})

	
	// 首页 
	$("#firstPage").bind("click", function() {
		var date = new Date();
		
		//后台
		var pageSize = $("#newsNum").html();

		var currentPage = $("#chooseFirst").html();
		var dName = $("#deptName").val();
		var beginTime = $("#beginTime").val();
	    var endTime = $("#endTime").val();
		
        if(currentPage>1){
        
        	
        	var url = "list";
    		var args = {
    			"psize" : pageSize,
    			"cpage" : 0,
    			"beginTime":beginTime,
    			"endTime":endTime,
    			"oaDept.deptName":dName
    		};		
    		$.post(url, args, function(data) {
    			$("#Cycle").empty();
				$.each(data, function(id, obj) {
			    var dat = new Date(obj.newDate);
			    var date =  dat.getFullYear() + '-' +dat. getMonth() + '-' +dat. getDate();
			    var time =  dat.getHours() + ':' + dat.getMinutes() + ':' +dat. getSeconds();
		        var tr = '<tr bgcolor="#FFFFF" height="35">'+

				'<td height="20" align="center"><input type="checkbox" name="delid" /></td>'+
				'<td class="tdNewOther" align="center">'+
				date+
				'</td>'+
				'<td class="tdNewTitle">'+
				obj.newTitle+'--'+
				'<span class="tdNewTime">'+
				time+
				'</span>'+
				'</td>'+
				'<td class="tdNewOther" align="center">'+obj.oaUser.userName+'</td>'+
					'<td class="tdNewOther" align="center">'+obj.oaDept.deptName+'</td>'+						
					'<td class="tdNewOther">&nbsp;&nbsp;&nbsp;</td>'+
					
					'</tr>'
		       
		        $("#Cycle").append(tr);
				
				});           		
				// 隔行变色
				$("tr:odd").addClass("odd");
				$("tr:even").addClass("even");
              
            })
    	
                     		
    		//页面部分
    		var chooseFirst = document.getElementById("chooseFirst");
    		chooseFirst.innerHTML = 1;
    		scrolltop(chooseFirst.innerHTML);

        }
				
	 
	})
	
	
	//上一页
	$("#lastPage").bind("click",function(){
		
		//页面部分
		var lastPage = document.getElementById("chooseFirst");
	    var num = lastPage.innerHTML;
	    if (num > 1) {
		num--;
		lastPage.innerHTML = num;
		var hei = 25 * num - 25;
		$("#chooseDiv").scrollTop(hei);
	    }
		
		
		
		
		//后台部分
		var pageSize = $("#newsNum").html();

		var currentPage = $("#chooseFirst").html();
		var c = (currentPage-1) * 10;
		var dName = $("#deptName").val();
		var beginTime = $("#beginTime").val();
	    var endTime = $("#endTime").val();

		var url = "list";
		var args = {
			"psize" : pageSize,
			"cpage" : c,
			"beginTime":beginTime,
			"endTime":endTime,
			"oaDept.deptName":dName
		};		
		$.post(url, args, function(data) {
			$("#Cycle").empty();
			$.each(data, function(id, obj) {
		    var dat = new Date(obj.newDate);
		    var date =  dat.getFullYear() + '-' +dat. getMonth() + '-' +dat. getDate();
		    var time =  dat.getHours() + ':' + dat.getMinutes() + ':' +dat. getSeconds();
	        var tr = '<tr bgcolor="#FFFFF" height="35">'+

			'<td height="20" align="center"><input type="checkbox" name="delid" /></td>'+
			'<td class="tdNewOther" align="center">'+
			date+
			'</td>'+
			'<td class="tdNewTitle">'+
			obj.newTitle+'--'+
			'<span class="tdNewTime">'+
			time+
			'</span>'+
			'</td>'+
			'<td class="tdNewOther" align="center">'+obj.oaUser.userName+'</td>'+
				'<td class="tdNewOther" align="center">'+obj.oaDept.deptName+'</td>'+						
				'<td class="tdNewOther">&nbsp;&nbsp;&nbsp;</td>'+
				
				'</tr>'
	       
	        $("#Cycle").append(tr);
			
			});           		
			// 隔行变色
			$("tr:odd").addClass("odd");
			$("tr:even").addClass("even");
       
        })
    
		
	});
	
	
	
	 // 下一页
	$("#nextPage").bind("click", function() {
		
      	//后台部分
		var pageSize = $("#newsNum").html();

		var currentPage = $("#chooseFirst").html();
		var finalPage = $("#chooseFinal").html();
		var dName = $("#deptName").val();
		var beginTime = $("#beginTime").val();
	    var endTime = $("#endTime").val();
		if(currentPage<finalPage){
			
			var c = currentPage * 10;
	        
			var url = "list";
			var args = {
				"psize" : pageSize,
				"cpage" : c,
				"beginTime":beginTime,
				"endTime":endTime,
				"oaDept.deptName":dName
			};		
			$.post(url, args, function(data) {
				$("#Cycle").empty();
				$.each(data, function(id, obj) {
			    var dat = new Date(obj.newDate);
			    var date =  dat.getFullYear() + '-' +dat. getMonth() + '-' +dat. getDate();
			    var time =  dat.getHours() + ':' + dat.getMinutes() + ':' +dat. getSeconds();
		        var tr = '<tr bgcolor="#FFFFF" height="35">'+

				'<td height="20" align="center"><input type="checkbox" name="delid" /></td>'+
				'<td class="tdNewOther" align="center">'+
				date+
				'</td>'+
				'<td class="tdNewTitle">'+
				obj.newTitle+'--'+
				'<span class="tdNewTime">'+
				time+
				'</span>'+
				'</td>'+
				'<td class="tdNewOther" align="center">'+obj.oaUser.userName+'</td>'+
					'<td class="tdNewOther" align="center">'+obj.oaDept.deptName+'</td>'+						
					'<td class="tdNewOther">&nbsp;&nbsp;&nbsp;</td>'+
					
					'</tr>'
		       
		        $("#Cycle").append(tr);
				
				});           		
				
				// 隔行变色
				$("tr:odd").addClass("odd");
				$("tr:even").addClass("even");
			
		
		
       
        })
		
		}
	  	 //页面部分		          
            var FinalPage = parseInt($("#chooseFinal").html());
    		var FirstPage = $("#chooseFirst");
    		var num = parseInt(FirstPage.html());
    		if (num < FinalPage) {
    			num = ++num;
    			FirstPage.html(num);
    			scrolltop(num);
    		}
            
		});       
		
	
	// 末页 
	$("#finalPage").bind("click", function() {
		
		
		
		//后台部分
		var pageSize = $("#newsNum").html();
		var dName = $("#deptName").val();
		var beginTime = $("#beginTime").val();
	    var endTime = $("#endTime").val();
		var currentPage = $("#chooseFirst").html();
		var finalPage = $("#chooseFinal").html();
		if(currentPage<finalPage){
			
			var c = (finalPage-1) * 10;

			var url = "list";
			var args = {
				"psize" : pageSize,
				"cpage" : c,
				"beginTime":beginTime,
				"endTime":endTime,
				"oaDept.deptName":dName
			};		
			$.post(url, args, function(data) {
				$("#Cycle").empty();
				$.each(data, function(id, obj) {
			    var dat = new Date(obj.newDate);
			    var date =  dat.getFullYear() + '-' +dat. getMonth() + '-' +dat. getDate();
			    var time =  dat.getHours() + ':' + dat.getMinutes() + ':' +dat. getSeconds();
		        var tr = '<tr bgcolor="#FFFFF" height="35">'+

				'<td height="20" align="center"><input type="checkbox" name="delid" /></td>'+
				'<td class="tdNewOther" align="center">'+
				date+
				'</td>'+
				'<td class="tdNewTitle">'+
				obj.newTitle+'--'+
				'<span class="tdNewTime">'+
				time+
				'</span>'+
				'</td>'+
				'<td class="tdNewOther" align="center">'+obj.oaUser.userName+'</td>'+
					'<td class="tdNewOther" align="center">'+obj.oaDept.deptName+'</td>'+						
					'<td class="tdNewOther">&nbsp;&nbsp;&nbsp;</td>'+
					
					'</tr>'
		       
		        $("#Cycle").append(tr);
				
				});           		
				
				$("tr:odd").addClass("odd");
				$("tr:even").addClass("even");
				
	        })
			
	      
	            
	            var chooseFirst = document.getElementById("chooseFirst");
	    		var chooseFinal = document.getElementById("chooseFinal");
	    		chooseFirst.innerHTML = chooseFinal.innerHTML;
	    		scrolltop(chooseFirst.innerHTML);
		
		}
		
		
	
	})

	
	// 显示几条记录
	$("#news").click(function(a) {

		$("#newsNumDiv").toggle();
		var newsNumUl = $("#newsNumUl");

		newsNumUl.empty();

		var num = [ "10", "20", "30", "50", "100" ];
		for (var i = 0; i < num.length; i++) {
			var L = "<li onclick='newfl(" + num[i] + ")'>" + num[i] + "</li>";
			newsNumUl.append(L);
		}	

	})

	
	// 动态获取一共有多少页
	var pageSize = $("#newsNum").html();
	var url = "getFinalPages";
	var args = {
		"psize" : pageSize
	};
	
	$.post(url, args, function(data) {
       
		$("#chooseFinal").html(data[0]);
	
     // 隔行变色
    	$("tr:odd").addClass("odd");
    	$("tr:even").addClass("even");
	});

	
	
})

// --------------------

function scrollTop(top) {
	var hei = 25 * top - 25;
	$("#chooseDiv").scrollTop(hei);

}



/* 确定第几页 */
function fl(p1) {
	$("tr:odd").addClass("odd");
	$("tr:even").addClass("even");
	$("#chooseFirst").empty();
	$("#chooseFirst").html(p1);
	
	var pageSize = $("#newsNum").html();
	var dName = $("#deptName").val();
	var beginTime = $("#beginTime").val();
    var endTime = $("#endTime").val();
	var currentPage = p1;
	var c = (currentPage-1) * 10;

	var url = "list";
	
	var args = {
		"psize" : pageSize,
		"cpage" : c,
		"beginTime":beginTime,
		"endTime":endTime,
		"oaDept.deptName":dName
	};
	
	$.post(url, args, function(data) {		
		$("#Cycle").empty();
		$.each(data, function(id, obj) {
	    var dat = new Date(obj.newDate);
	    var date =  dat.getFullYear() + '-' +dat. getMonth() + '-' +dat. getDate();
	    var time =  dat.getHours() + ':' + dat.getMinutes() + ':' +dat. getSeconds();
        var tr = '<tr bgcolor="#FFFFF" height="35">'+

		'<td height="20" align="center"><input type="checkbox" name="delid" /></td>'+
		'<td class="tdNewOther" align="center">'+
		date+
		'</td>'+
		'<td class="tdNewTitle">'+
		obj.newTitle+'--'+
		'<span class="tdNewTime">'+
		time+
		'</span>'+
		'</td>'+
		'<td class="tdNewOther" align="center">'+obj.oaUser.userName+'</td>'+
			'<td class="tdNewOther" align="center">'+obj.oaDept.deptName+'</td>'+						
			'<td class="tdNewOther">&nbsp;&nbsp;&nbsp;</td>'+
			
			'</tr>'
       
        $("#Cycle").append(tr);
		
		});           	
		// 隔行变色
		$("tr:odd").addClass("odd");
		$("tr:even").addClass("even");
	})
	
	
		    
		   
	   
}

function newfl(p1) {
	$("#newsNum").empty();
	$("#newsNum").html(p1);
	var flag;
	// 动态获取一共有多少页
	var pageSize = $("#newsNum").html();
	var url = "getFinalPages";
	var dName = $("#deptName").val();				
	var beginTime = $("#beginTime").val();
    var endTime = $("#endTime").val();
    if(beginTime !=null && beginTime !="" ||endTime!=null && endTime!=""||dName!=null && dName!=""){    	
    	
    	flag=0;
    }else{
    	
    	flag=1;
    }
    
	var args = {
		"psize" : pageSize,
		"beginTime":beginTime,
		"endTime":endTime,
		"oaDept.deptName":dName,
		"flag":flag
	};
	
	$.post(url, args, function(data) {
       
		$("#chooseFinal").html(data[0]);
	
     // 隔行变色
    	$("tr:odd").addClass("odd");
    	$("tr:even").addClass("even");
	});
	
	
	
	
	var pageSize = p1;
	   
	var currentPage =$("#chooseFirst").html(); 
	var c = (currentPage-1) * 10;

	var url = "list";
	
	var args = {
		"psize" : pageSize,
		"cpage" : c,
		"beginTime":beginTime,
		"endTime":endTime,
		"oaDept.deptName":dName
	};
	
	$.post(url, args, function(data) {		
		$("#Cycle").empty();
		$.each(data, function(id, obj) {
	    var dat = new Date(obj.newDate);
	    var date =  dat.getFullYear() + '-' +dat. getMonth() + '-' +dat. getDate();
	    var time =  dat.getHours() + ':' + dat.getMinutes() + ':' +dat. getSeconds();
        var tr = '<tr bgcolor="#FFFFF" height="35">'+

		'<td height="20" align="center"><input type="checkbox" name="delid" /></td>'+
		'<td class="tdNewOther" align="center">'+
		date+
		'</td>'+
		'<td class="tdNewTitle">'+
		obj.newTitle+'--'+
		'<span class="tdNewTime">'+
		time+
		'</span>'+
		'</td>'+
		'<td class="tdNewOther" align="center">'+obj.oaUser.userName+'</td>'+
			'<td class="tdNewOther" align="center">'+obj.oaDept.deptName+'</td>'+						
			'<td class="tdNewOther">&nbsp;&nbsp;&nbsp;</td>'+
			
			'</tr>'
       
        $("#Cycle").append(tr);
		
		});           	
		
		// 隔行变色
		$("tr:odd").addClass("odd");
		$("tr:even").addClass("even");
	});
	
	
}
